home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / Graphic Gems I, II & III (C_C++) / Graphics Gems C Code.sea / GemsIII / simplex / symm.C < prev   
Text File  |  1992-06-16  |  1KB  |  37 lines

  1. /***********************************************************
  2. Given an s-simplex (with s+1 vertexes) in n dimensions,
  3. calculate the vertexes of the kth (0 <= k < (1<<s))
  4. subsimplex in the symmetric subdivision of the simplex.
  5.  
  6. Several implementations of the bitCount() function are
  7. described in "Of Integers, Fields, and Bit Counting",
  8. Paeth and Schilling, Graphics Gems II.
  9.  
  10. Entry:
  11.   src_vtx - list of the vertexes of the original simplex
  12.   n - each n consecutive floats represents one vertex
  13.   s - there are s+1 vertexes in the s-simplex
  14.   k - identifies which subsimplex is to be generated
  15. Exit:
  16.   dst_vtx - list of the vertexes of the kth subsimplex
  17.   
  18. ***********************************************************/
  19. void sym_subsimplex(register float* dst_vtx,
  20.                     const float* const src_vtx,
  21.                     int n,
  22.                     int s,
  23.                     int k)
  24. {
  25.   int id[2];
  26.   id[1] = n*bitCount(k);
  27.   id[0] = 0;
  28.   
  29.   for (int j = 0; j <= s; ++j)
  30.     {
  31.       for (int i = 0; i < n; ++i)
  32.         *dst_vtx++ = (src_vtx[i+id[0]] + src_vtx[i+id[1]]) / 2.0;
  33.       id[!(k&1)] += n;
  34.       k >>= 1;
  35.     }
  36. }
  37.